package nl.hanze.web.gba.doa.impl;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class BasePersistence {
	protected EntityManagerFactory emf;
    protected EntityManager em;

    public void open() {
        if (emf == null || !emf.isOpen()) {
            emf = Persistence.createEntityManagerFactory("week3_opdracht3");
        }
        
        if (em == null || !em.isOpen()) {
            em = emf.createEntityManager();
        } 
    }

    protected void close() {
        em.close();
        emf.close();
    }
}
